package org.git.movie;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.git.movie.filters.TraceIdFilter;
//import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@SpringBootApplication
@ServletComponentScan(basePackageClasses = {TraceIdFilter.class})
@MapperScan(basePackages = {"org.git.movie.mapper"})
@Slf4j
public class OpenMovieApplication {

    /**
     * 集成sentinel时设置jvm参数为：
     * -Dcsp.sentinel.config.file=classpath:sentinel.properties
     * @param args
     * @throws UnknownHostException
     */
    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(OpenMovieApplication.class, args);

        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        if(StringUtils.isEmpty(path)){
            path = "";
        }
        log.info("\n----------------------------------------------------------\n\t" +
                "Application OpenMovieApplication is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + port + path + "/\n\t" +
                "External: \thttp://" + ip + ":" + port + path + "/\n\t" +
                "----------------------------------------------------------");
        log.info("启动完毕");
    }

}
